<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>织梦无忧助手官方采集器</title>
    <meta name="keywords" content="织梦无忧助手官方采集器" />
    <meta name="description" content="织梦无忧助手官方采集器！" />
    <link rel="stylesheet" href="/static/style/css/index.css" />
    <script
      type="text/javascript"
      src="/static/style/js/jquery1.42.min.js"
    ></script>
    <style>
      form#posturl {
        width: 100%;
        text-align: center;
        padding: 100px 0 50px;
      }
      input#url {
        padding: 0 5px;
        width: 400px;
        border: 2px solid #bbb;
        line-height: 24px;
        margin-right: 5px;
      }
      #encodebox div {
        padding: 10px;
      }
      h1,
      h2 {
        font-weight: normal;
        padding: 10px;
        color: red;
      }
      #mainbox {
        margin: 0 auto;
        width: 70%;
      }
      .lodingimg {
        display: block;
        max-width: 600px;
        margin: 0 auto;
      }
      textarea {
        width: 96%;
        min-height: 165px;
        border-radius: 5px;
        margin: 5px 2%;
        padding: 5px;
      }
      .text_change {
        width: auto;
        height: auto;
        line-height: 2em;
      }
      h4 {
        text-align: center;
      }
    </style>
  </head>
  <body>
    <form method="" method="post" id="posturl">
      <input
        type="text"
        id="url"
        name="url"
        placeholder="请输入文章详情页网址"
        value=""
      />
      <button class="text_change">分析页面内容</button>
      <input type="hidden" name="APPID" value="2020325130955" />
      <input type="hidden" name="APPKEY" value="f46sda54f6ds4fd4sa86f4dsfdsa" />
      <input
        type="hidden"
        name="POSTCALL"
        value="https://www.baidu.com/get.php"
      />
      <input type="hidden" name="ARCTYPE" value="0" />
      <!--		<input type="hidden" name="KEYWORDLIST" value="羊毛出在羊身上|武汉 | 新冠病毒|美国|阴谋|王健林|马云" />-->
      <!-- <input type="hidden" name="KEYWORDLIST" value="马云" /> -->
      <input type="hidden" name="LGCODE" value="0" />
      <input type="hidden" name="REGULAR" value="0.1" />

      <input type="hidden" name="MODE" value="1" />
      <input
        type="hidden"
        name="ARCURL"
        value="https://study.163.com/course/courseLearn.htm?courseId=1006129049#/learn/video?lessonId=1053565012&courseId=1006129049"
      />
    </form>
    <div id="mainbox">
      <h1>数据分析结果</h1>
      <h4>
        （当前本功能处于测试阶段，基于AI自学习技术，越用越强大，当前因为训练模型数据不够充足，能识别市面上绝大多数文章内容，但是不保证一定获取准确，数据仅供参考！当训练量达到一定程度，将会越来越完善！）
      </h4>
      <div id="encodebox"></div>
    </div>
  </body>
  <script>
    var ws = null;
    $(function () {
      WebSocketTest("admin:123456");
      //console.log(ws.send(dataval));
    });

    function WebSocketTest(data) {
      //data = $("#inpws").val();
      if ("WebSocket" in window) {
        // 打开一个 web socket
        ws = new WebSocket("ws://127.0.0.1:5678");
        // 连接建立后的回调函数
        ws.onopen = function () {
          ///校验appkey
          ws.send(data);
          $("#encodebox").append("正在发送：" + data + "</br>");
        };
        // 接收到服务器消息后的回调函数
        ws.onmessage = function (evt) {
          var received_msg = evt.data;
          console.log(evt);
          if (received_msg.indexOf("sorry") == -1) {
            $("#encodebox").append("收到消息：" + received_msg + "</br>");
          }
        };
        // 连接关闭后的回调函数
        ws.onclose = function () {
          // 关闭 websocket
          alert("连接已关闭...");
        };
        //=========启动一个websocket
      } else {
        // 浏览器不支持 WebSocket
        alert("您的浏览器不支持 WebSocket!");
      }
    }

    function Setsocket(dataval) {
      // Web Socket 已连接上，使用 send() 方法发送数据
      //var val = $("#inpws").val();
      console.log(ws.send(dataval));
      $("#encodebox").append("正在发送：" + dataval + "</br>");
      //return
    }

    $("button.text_change").click(function () {
      // Setsocket(JSON.stringify($('form').serializeJson()));
      // return false;
      $.ajax({
        type: "POST",
        url: "/getarticle.php",
        cache: "false",
        dataType: "json",
        timeout: 10000,
        data: $("form").serializeArray(),
        beforeSend: function () {
          //提交的数据前做一些操作
          //alert("this is before send");
          $("button.text_change").attr({ disabled: true });
          $("button.text_change").html("提取中。。。");
          $("#encodebox").html(
            "<img class='lodingimg' src='/static/style/images/timg.gif' />"
          );
        },

        success: function (data) {
          $("#encodebox").html(
            "<h2><span>标题:</span></h2>" +
              "<div class='article_title'>" +
              data.title +
              "</div>" +
              "<h2><span>可能的首图URL:</span></h2>" +
              "<div class='article_topimg'>" +
              data.top_image +
              "</div>" +
              "<h2><span>文章中视频的url:</span></h2>" +
              "<div class='article_htmltxt'>" +
              data.movies +
              "</div>" +
              "<h2><span>包含html的文章主内容:</span></h2>" +
              "<div class='article_htmltxt'>" +
              data.article_html +
              "</div>" +
              "<h2><span>去除html的文章主内容:</span></h2>" +
              "<div class='article_txt'>" +
              data.text +
              "</div>" +
              "<h2><span>作者:</span>" +
              data.authors +
              "</h2>" +
              "<h2><span>文章摘要:</span>" +
              data.summary +
              "</h2>"
          );
          $("#encodebox").append(data);
        },
        error: function () {
          alert("完了，出现了一些错误，您可以加官方群咨询群主！");
          $("button.text_change").attr({ disabled: false });
          $("button.text_change").html("分析页面内容");
        },
        complete: function () {
          $("button.text_change").attr({ disabled: false });
          $("button.text_change").html("分析页面内容");
        },
      });
    });
    //表单序列化为json对象
    // $.fn.serializeJson = function () {
    //   var serializeObj = {};
    //   var array = this.serializeArray();
    //   var str = this.serialize();
    //   $(array).each(function () {
    //     if (serializeObj[this.name]) {
    //       if ($.isArray(serializeObj[this.name])) {
    //         serializeObj[this.name].push(this.value);
    //       } else {
    //         serializeObj[this.name] = [serializeObj[this.name], this.value];
    //       }
    //     } else {
    //       serializeObj[this.name] = this.value;
    //     }
    //   });
    //   return serializeObj;
    // };
  </script>
</html>
